import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import { Button } from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import ListTable from "./Components/ListTable";
import MaintainAdd from "./Components/MaintainAdd";

@connect()

export default class EquipmentList extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      modalAddVisible: false,
      detailId: 0,
      detailInfoId: 0,
      detailInfoName:null,
      isReloadList:false,
    };
  }

  componentWillUnmount(){
    const { dispatch } = this.props;
    dispatch({
      type: `equipment_maintain/appendClearState`,
    })
  }

  componentDidMount() {
    const { dispatch } = this.props;
    // 数据字典
    // dispatch({
    //   type: 'global/fetch_dictionar',
    //   // payload:["devType", "status", "whitelistReason"]
    // });
    // 维保单位列表
    // dispatch({
    //   type: 'global/fetch_select_maintencompany',
    // });
  }

  // 暂停数据回拉
  sotpReloadList = () =>{
    this.setState({
      isReloadList:false,
    });
  }

  // 显示新增修改model
  handleMaintainModalVisible= flag => {
    this.setState({
      modalAddVisible: !!flag,
    });
  };

  // 设备新增、编辑后model回调
  handleMaintainModelCallBack=()=>{
    this.handleMaintainModalVisible(false);
    this.setState({
      isReloadList:true,
    });
  }

  // 编辑设备
  handleEditMaintain = id => {
    this.setState(
      {detailId: id},
      () => {
        this.handleMaintainModalVisible(true);
      }
    );
  };

  // 展示详情
  handleMaintainInfo= (id,name) => {
    this.setState(
      {
        detailInfoId: id,
        detailInfoName:name
      }
    );
  };




  render() {
    const { dictionaries, location } = this.props;
    const { modalAddVisible, detailId, isReloadList } = this.state;
    const pagesquery = location.query;


    return (
        <PageHeaderLayout >
          <ListTable
            dictionaries={dictionaries}
            addModelCallBack={this.handleEditMaintain}
            detailModelCallBack={this.handleMaintainInfo}
            sotpReloadList={this.sotpReloadList}
            isReloadList={isReloadList}
            pagesquery={pagesquery}
          />

          <MaintainAdd
            visible={modalAddVisible}
            onCancel={e => this.handleMaintainModalVisible(e)}
            callback={this.handleMaintainModelCallBack}
            detailId={detailId}
            dictionaries={dictionaries}
          />

        </PageHeaderLayout>

    );
  }
}
